package org.hy.corn_task.controller;

import org.hy.corn_task.pojo.entity.source.Dept;
import org.hy.corn_task.service.source.DeptService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import okhttp3.Headers;
import org.hy.corn_task.service.target.YsgzBdcR1Service;
import org.hy.corn_task.utils.ExeTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @Description: DeptController控制类
 * @Author: WangBlue
 * @Create: 2024-08-23
 **/
@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @Autowired
    YsgzBdcR1Service ysgzBdcR1Service;


    @RequestMapping("/id")
    public Dept getDeptById(Integer id) {
        return deptService.getDeptById(id);
    }

//    @GetMapping("/test")
//    public IPage<Dept> test() {
//        PageQuery<Dept> page = new PageQuery<>();
//        return deptService.selectDeptPage(page);
//    }

    @GetMapping("/test2")
    public void test2() {
        //准备请求参数
        String url = "http://localhost:8080/cron-test";
        List<Dept> list = deptService.list();
        Headers header = new Headers.Builder().add("Content-Type", "application/x-www-form-urlencoded")
                .add("apikey", "pizqxE4BORUR6xje6CseWkjLB6aegrxS").build();

        ExeTask exeTask = new ExeTask();

        for (Dept item : list) {
            //执行请求
            try {
                exeTask.exeAPITask(url,header,item);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }


}
